﻿using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using StoreDemo.Domain.Data;
using StoreDemo.Domain.Entities;
using StoreDemo.Domain.Services;

namespace StoreDemo.Domain.Test.Unit.Experimental.Services.Products
{
    [TestFixture]
    public class ProductServiceTests
    {
        [TestFixture]
        public class GetAll
        {
            [Test]
            public void ReturnsAllProductsFromTheRepositor()
            {
                //Arrange
                Mock<IUnitOfWorkFactory> unitOfWorkFactoryMock = new Mock<IUnitOfWorkFactory>();
                Mock<IUnitOfWork> unitOfWorkMock = new Mock<IUnitOfWork>();
                Mock<IRepository<Product>> productRepository = new Mock<IRepository<Product>>();
                IQueryable<Product> products = new List<Product>().AsQueryable();
                productRepository.Setup(x => x.All).Returns(products);
                unitOfWorkMock.Setup(x => x.GetRepository<Product>()).Returns(productRepository.Object);
                unitOfWorkFactoryMock.Setup(x => x.GetUnitOfWork()).Returns(unitOfWorkMock.Object);

                //Act
                IProductService sut = new ProductService(unitOfWorkFactoryMock.Object);
                IEnumerable<Product> returnedProducts = sut.GetAllProducts();

                //Assert
                CollectionAssert.AreEqual(products, returnedProducts);
            }
        }
    }
}